<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>分享详情</title>
    <meta id="viewport" name="viewport"
          content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
    <meta name="format-detection" content="telephone=no">
    <link href="<c:url value='/resource/css/main.css' />" type="text/css" rel="stylesheet">
    <link href="<c:url value='/resource/css/iconfont.css' />" type="text/css" rel="stylesheet">
</head>

<body>
<div class="container" id="share-container">
    <header class="module-topbar">
        <a class="fl" href="javascript:history.back();"><i class="iconfont">&#xe608;</i><spring:message code="back"/></a>
        <span><spring:message code="detail"/></span>
    </header>
    <div id="wapper-pull" class="margin-topbar padding-container">
        <div class="module-shares">
        </div>
    </div>
</div>

<script type="text/javascript" src="${basePath}/resource/js/common/messages_${sessionScope.lang}.js"></script>
<script type="text/javascript" src="${basePath}/resource/js/share/jquery.min.js"></script>
<script type="text/javascript" src="${basePath}/resource/js/share/laytpl.js"></script>
<script type="text/javascript" src="${basePath}/resource/js/share/layer/layer.m.js"></script>
<script type="text/javascript" src="${basePath}/resource/js/share/swipeSlide.js"></script>
<script type="text/javascript" src="${basePath}/resource/js/share/jquery.lazyload.min.js"></script>
<script type="text/javascript" src="${basePath}/resource/js/share/json2.js"></script>
<script type="text/javascript" src="${basePath}/resource/js/share/share.js"></script>
<script id="tpl" type="text/html">
    {{# var share = d;}}
    <div class="share detail line-around" id="{{ share.id }}" {{# if (share.type == '1'){ }}original="{{ share.original }}"{{# } }}>
		<jsp:include page="tpl/header.jsp" />
		<div class="wj-detail-box">
        	<jsp:include page="tpl/detail.jsp" />
        	<jsp:include page="tpl/interact.jsp" />
        <section class="interact-detail wj-interact-detail {{# if (share.comments.length <= 0 && share.forwards.length <= 0 && share.likes.length <= 0 ) { }}wj-interact-details-none{{# } }}">
            <jsp:include page="tpl/forwardAndLike.jsp" />
            {{# if (share.comments.length > 0) { }}
            {{# for(var j = 0, len1 = share.comments.length; j < len1; j++){var comment = share.comments[j], from = comment.from; }}
            <section>
                <header class="layout-box">
                    <a href="<c:url value='/u/{{from.id}}.do' />" class="mod-avatar" uid="{{ from.id }}"><div class="avatar"><img src="{{from.avatar}}" onerror="$(this).attr('src','http://123.57.249.184/i/defaultAvatar/moren_icon.png')"></div></a>

					{{# var create_time;}}
    				{{# var strs= new Array();}}
    				{{# strs = comment.time.split(',');}}
    				{{# if(strs.length > 1){ }}
    				{{# if(strs[2] == '1'){ }}
    					{{# create_time = strs[0]+' ' + messages.secs;}} 
    				{{# }else if(strs[2] == '2'){ }}
    					{{# create_time = strs[0] +' '+ messages.sec;}} 
   		 			{{# }else if(strs[2] == '3'){ }}
    					{{# create_time = strs[0] +' '+ messages.mins;}}
    				{{# }else if(strs[2] == '4'){ }}
    					{{# create_time = strs[0] +' '+ messages.min;}}
    				{{# }else if(strs[2] == '5'){ }}
    					{{# create_time = messages.today+strs[0];}}
    				{{# }else if(strs[2] == '6'){ }}
    					{{# create_time = messages.yesterday + strs[0];}}
    				{{# } }}
    				{{# }else{ }}
    					{{# create_time = comment.time;}}
    				{{# } }}
                    <div class="box-col mod-info wj-inner-mod-info"><a href="<c:url value='/u/{{from.id}}.do' />">{{ from.name }}</a><div class="time">{{ create_time }}</div></div>
                    {{# if (from.id != Page.getUser().id) { }}
                    <a class="operate-box"><i class="iconfont selected">&#xe601;</i> <spring:message code="reply"/></a>
                    {{# }}}
                </header>
                <aside>
                    <p class="txt-l" msgId="{{comment.msgId}}"><a class="hid" uid="{{from.id}}">{{ from.name }}</a>{{ comment.text }}{{# if (from.id == Page.getUser().id) { }}<i class="iconfont delete hid">&#xe619;</i>{{# }}}</p>
                    {{# if (comment.replies && comment.replies.length > 0) { }}
                    {{# for(var k = 0, len2 = comment.replies.length; k < len2; k++){var reply = comment.replies[k], referFrom = reply.from; }}
                    <p class="txt-l" msgId="{{reply.msgId}}">
                        <a href="<c:url value='/u/{{referFrom.id}}.do' />" uid="{{referFrom.id}}">{{referFrom.name}}</a>{{# if (reply.refer) { }}<spring:message code="reply"/><a href="<c:url value='/u/{{reply.to.id}}.do' />">{{reply.to.name}}</a>{{# }}}：{{reply.text}}
                        {{# if (referFrom.id != Page.getUser().id) { }}
                        <i class="iconfont">&#xe601;</i>
                        {{# } else { }}
                        <i class="iconfont delete hid">&#xe619;</i>
                        {{# }}}
                    </p>
                    {{# }}}
                    {{# }}}
                </aside>
            </section>
            {{# }}}
            {{# }}}
           <%-- <p class="txt-l comment"><spring:message code="inputComment"/>...</p> --%>
        </section>
		</div>
    </div>
</script>
<script>

    var feed;
    var userId = Page.getUser().id;
    var share = <%=request.getAttribute("share")%>;
    $(share.likes).each(function(index, like){
        if (like.from.id = userId) {
            share.liked = true;
            return false;
        }
    });

    function loadShares(feeds, clear) {
        laytpl(document.getElementById('tpl').innerHTML).render(feeds, function (html) {
            var shares = $(html);
            shares.find('img.loading').lazyload({
                threshold : 200,
                effect: "fadeIn"
            });

            if (clear) {
                $('.module-shares').empty();
            }
            shares.appendTo($('.module-shares'));
            $(shares).each(function() {
                feed.bindShare($(this));
            });
        });
    }
    
    $(function () {
    	feed = Feed.create($('.module-shares'), Share.create($('.module-publisher')));
       /*  laytpl(document.getElementById('tpl').innerHTML).render(share, function (html) {
            $('.module-shares').html(html).find('img.loading').lazyload();
        });
        feed = Feed.create($('.module-shares'), Share.create($('.module-publisher')).bindPopstate()); */
        loadShares(share);
        
        $('.goUserInfo').click(function() {
	        var userName = $(this).text();
	        userName = userName.replace(/\@/g, "")
	        var lang = localStorage.getItem("lang");
	        var userToken = localStorage.getItem("userTonken");
	        // n/名称.do
	        var action = '${basePath}/n/'+ userName + '.do?userToken='+userToken+'&lang='+lang;
	        window.location.href = action;
        	
        })

    });

    function reload(share) {
        laytpl(document.getElementById('tpl').innerHTML).render(share, function (html) {
            $('.module-shares').empty();
            feed.bindShare($(html).appendTo($('.module-shares')));
        });
    }
</script>

<jsp:include page="comment.jsp"/>
<jsp:include page="swipe.jsp"/>
</body>

</html>
